package com.netrust.cmsx.core.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class RequestExcuteTimeFilter implements Filter{
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		  HttpServletRequest httpRequest = (HttpServletRequest)request;
		  String url = httpRequest.getServletPath();
	  
	  if(checkUrl(url)){ 
		  long a=System.currentTimeMillis();
		  chain.doFilter(request, response); // 继续执行
		  System.out.println("地址："+url+" ,执行耗时 : "+(System.currentTimeMillis()-a)/1000f+" 秒 ");
	  }else{
	   chain.doFilter(request, response); // 继续执行
	  }
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		
	}


	public void destroy() {
		// TODO Auto-generated method stub
		
	}
	
	public boolean checkUrl(String url){
		if(url.contains("static")){
			return false;
		}
		return true;
	}
}
